/*
 * This file is part of VLCJ.
 *
 * VLCJ is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VLCJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VLCJ.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Copyright 2009, 2010, 2011 Caprica Software Limited.
 */

package uk.co.caprica.vlcj.dbus.sessionmanager;

import org.freedesktop.dbus.UInt32;

import uk.co.caprica.vlcj.dbus.AbstractDBusInterface;
import uk.co.caprica.vlcj.dbus.DBusSession;

/**
 * A helper class that interacts with the Gnome Session Manager through the 
 * DBus.
 */
public class DBusSessionManagerInterface extends AbstractDBusInterface {

  /**
   * Screen Saver object path.
   */
  private static String OBJECT_PATH = "/org/gnome/SessionManager";

  /**
   * Screen Saver service bus name.
   */
  private static String SERVICE_BUS_NAME = "org.gnome.SessionManager";

  /**
   * Create a DBus interface wrapper.
   * 
   * @param dbusSession session 
   */
  public DBusSessionManagerInterface(DBusSession dbusSession) {
    super(dbusSession, OBJECT_PATH, SERVICE_BUS_NAME);
  }

  /**
   * Inhibit the session manager.
   * 
   * @param applicationName application name
   * @param inhibitReason message stating why the session manager is inhibited
   * @return cookie, used later to uninhibit the session manager, or <code>null</code> if the session manager could not be inhibited
   */
  public UInt32 inhibit(String applicationName, String inhibitReason) {
    SessionManager sessionManager = service(SessionManager.class);
    return sessionManager.Inhibit(applicationName, new UInt32(0), inhibitReason, new UInt32(4+8));
  }

  /**
   * Uninhibit the session manager.
   * 
   * @param cookie cookie, obtained earlier when inhibiting the power manager
   */
  public void unInhibit(UInt32 cookie) {
    SessionManager sessionManager = service(SessionManager.class);
    sessionManager.Uninhibit(cookie);
  }
}